package com.hlhj.funlike_business.activity.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hlhj.funlike_business.R;
import com.hlhj.funlike_business.activity.AddCommentyAty;
import com.hlhj.funlike_business.bean.FoodListBean;

import java.util.List;

public class FoodListAdp extends BaseQuickAdapter<FoodListBean.DataBeanX.DataBean,BaseViewHolder> {
    public FoodListAdp(@Nullable List<FoodListBean.DataBeanX.DataBean> data) {
        super(R.layout.adp_foodlist,data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final FoodListBean.DataBeanX.DataBean item) {
        ImageView img_foodlist = helper.getView(R.id.img_foodlist);
        TextView tv_shopname = helper.getView(R.id.tv_shopname);
        TextView tv_sell = helper.getView(R.id.tv_sell);
        TextView tv_foodcontent = helper.getView(R.id.tv_foodcontent);
        TextView tv_shopprice = helper.getView(R.id.tv_shopprice);
        final TextView tv_xiajia = helper.getView(R.id.tv_xiajia);
        final TextView tv_bianji = helper.getView(R.id.tv_bianji);
        final RelativeLayout tv_soldout = helper.getView(R.id.rl_soldout);
        final RelativeLayout rl_item = helper.getView(R.id.rl_item);

        Glide.with(mContext).load(item.getPhoto()).into(img_foodlist);
        tv_shopname.setText(item.getGoods_name());
        tv_sell.setText("月售:" + item.getSell_num());
        tv_foodcontent.setText(item.getDescribe());
        tv_shopprice.setText("￥" + item.getDiscount_price());

        if (item.getStatus()==1){
            tv_soldout.setVisibility(View.GONE);
            tv_xiajia.setText("下架");
            tv_xiajia.setVisibility(View.VISIBLE);
            tv_xiajia.setTextColor(mContext.getResources().getColor(R.color.black));
            tv_xiajia.setBackground(mContext.getResources().getDrawable(R.drawable.bg_xiajia));
        }else {
            tv_soldout.setVisibility(View.VISIBLE);
            tv_xiajia.setText("上架");
            tv_xiajia.setVisibility(View.VISIBLE);
            tv_xiajia.setTextColor(mContext.getResources().getColor(R.color.white));
            tv_xiajia.setBackground(mContext.getResources().getDrawable(R.drawable.bg_shangjia));
        }

        rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.showListener(item.getId());
                }
            }
        });
        tv_xiajia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null){
                    if (tv_xiajia.getText().toString().equals("上架")){
                        listener.showResult(item.getId(),0,helper.getAdapterPosition());
                    }else {
                        listener.showResult(item.getId(),1,helper.getAdapterPosition());
                    }
                }
            }
        });
        tv_bianji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext,AddCommentyAty.class);
                intent.putExtra("id",item.getId());
                intent.putExtra("type",1);
                mContext.startActivity(intent);
            }
        });
    }

    public interface getResult{
        void showResult(int id,int status,int postion);

        void showListener(int id);
    }

    public getResult listener;

    public void setListener(getResult listener) {
        this.listener = listener;
    }
}
